package com.qf.service.impl;

import com.qf.entity.Admini;
import com.qf.mapper.HospMapper;
import com.qf.service.HospService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Service
public class HospServiceImpl implements HospService {

    @Autowired
    private HospMapper hospMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public Admini login(Admini admini) {

        return hospMapper.login(admini);
    }

    @Override
    public Admini getInfo() {
        //处理头部请求
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        String token = request.getHeader("X-Token");

       Admini adminiInfo = (Admini) redisTemplate.opsForValue().get("user:" + token);
        return adminiInfo;
    }
}
